package dbase;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import model.anggota;
/**
 *
 * @author aa
 */
public class DBregister {
    Connection conn;

    public DBregister(Connection conn){
        this.conn = conn;
    }

    public void insertRegister(String nrp, String nama, String alamat, String status) throws Exception {
        String sql = "INSERT INTO anggota (nrp,nama, alamat, statusAnggota) VALUES(?,?, ?, ?)";
        PreparedStatement st = conn.prepareStatement(sql);
        st.setString(1, nrp);
        st.setString(2, nama);
        st.setString(3, alamat);
        st.setString(4, status);
        st.executeUpdate();
        st.close();
    }

    public anggota cekAnggota(String nrp) throws Exception {
        anggota anggota1 = null;
        String sql = "SELECT * FROM pengguna WHERE nrp=?";
        PreparedStatement st = this.conn.prepareStatement(sql);
        st.setString(1, nrp);
        ResultSet rs = st.executeQuery();
        if(rs.next()){
            anggota1 = new anggota();
            anggota1.setIdAnggota(rs.getInt(1));
            }
        return anggota1;
    }


}
